home *** CD-ROM | disk | FTP | other *** search
- package horst;
-
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Rectangle;
- import java.awt.Shape;
- import java.util.Enumeration;
- import java.util.Vector;
-
- public class TableView extends BlockView {
- static final int TOP_VALIGN = 0;
- static final int MIDDLE_VALIGN = 1;
- static final int BOTTOM_VALIGN = 2;
- static final int BASELINE_VALIGN = 3;
- private static final int PREFWIDTH = 0;
- private static final int MINWIDTH = 1;
- private static final int LAYOUT = 2;
- View[] m_topCaptions;
- View[] m_bottomCaptions;
- boolean[] m_hasSingleCell;
- int[] m_prefColWidths;
- int[] m_minColWidths;
- int[] m_colWidths;
- int[] m_colSpecWidths;
- int[] m_rowHeightSpecs;
- float[] m_pctColWidths;
- boolean m_bHavePctColumns;
- boolean m_bPrefMinColsComputed = false;
- Rectangle m_tableBorder;
- float m_pctValue;
- Color m_bgColor;
- int m_nColumns;
- int m_nRows;
- int m_nDefinedRows;
- int m_cellPadding;
- int m_cellSpacing;
- int m_borderSize;
- int m_width;
- int m_height;
-
- public TableView(View parent, Element e, HTMLPane container) {
- super(parent, e, container);
- }
-
- boolean allMinimum(int[] cols) {
- for(int i = 0; i < cols.length; ++i) {
- if (cols[i] > this.m_minColWidths[i]) {
- return false;
- }
- }
-
- return true;
- }
-
- boolean allSpecWidths(int[] cols) {
- for(int i = 0; i < cols.length; ++i) {
- if (this.m_colSpecWidths[i] != -1 && cols[i] > this.m_minColWidths[i] && cols[i] > this.m_colSpecWidths[i]) {
- return false;
- }
- }
-
- return true;
- }
-
- void checkWidthSpecification(int width) {
- int diff = 0;
- int span = 0;
- if (this.m_width != -1) {
- span = this.getColumnSum(this.m_colWidths);
- int specWidth = this.m_width;
- specWidth -= 2 * this.m_borderSize;
- specWidth -= 2 * this.m_cellSpacing + (this.m_nColumns - 1) * this.m_cellSpacing;
- if (specWidth > span) {
- diff = specWidth - span;
- }
- } else if (this.m_pctValue > 0.0F && this.m_pctValue <= 1.0F) {
- span = this.getColumnSum(this.m_colWidths);
- diff = Math.max(0, width - span);
- }
-
- if (diff > 0) {
- int runningTotal = 0;
- int addAmount = 0;
-
- for(int i = 0; i < this.m_colWidths.length; ++i) {
- if (i == this.m_colWidths.length - 1) {
- addAmount = diff - runningTotal;
- } else {
- double pct = (double)this.m_colWidths[i] / (double)span;
- addAmount = (int)(pct * (double)diff);
- }
-
- int[] var10000 = this.m_colWidths;
- var10000[i] += addAmount;
- runningTotal += addAmount;
- }
- }
-
- }
-
- protected boolean columnOccupied(Vector v, int row, int col) {
- Enumeration e = v.elements();
-
- while(e.hasMoreElements()) {
- RowSpanColumns x = (RowSpanColumns)e.nextElement();
- if (row <= x.endRow) {
- for(int i = 0; i < x.columns.length; ++i) {
- if (x.columns[i] == col) {
- return true;
- }
- }
- }
- }
-
- return false;
- }
-
- int[] computeColumnWidths(int width, int mode) {
- int[] widths = new int[this.m_nColumns];
-
- for(int pass = 0; pass < 2; ++pass) {
- if (mode == 0) {
- widths = Utilities.clone(this.m_prefColWidths);
- } else if (mode == 1) {
- widths = Utilities.clone(this.m_minColWidths);
- } else {
- widths = pass == 0 ? Utilities.clone(this.m_prefColWidths) : Utilities.clone(this.m_minColWidths);
- }
-
- for(int row = 0; row < super.m_children.length; ++row) {
- View[] cells = ((TableRow)super.m_children[row]).m_children;
-
- for(int cellNum = 0; cellNum < cells.length; ++cellNum) {
- TableCell cell = (TableCell)cells[cellNum];
- if (cell.m_colSpan > 1) {
- int startCol = cell.m_startColumn;
- int endCol = cell.m_endColumn;
- int spanWidth = 0;
-
- for(int j = startCol; j <= endCol; ++j) {
- spanWidth += widths[j];
- }
-
- int cellSpan = 0;
- if (mode == 1) {
- cellSpan = cell.getMinimumSpan(1);
- } else if (mode == 0) {
- cellSpan = cell.getPreferredSpan(1);
- } else {
- cellSpan = pass == 0 ? cell.getPreferredSpan(1) : cell.getMinimumSpan(1);
- }
-
- if (cellSpan > spanWidth) {
- widths = this.distributeSpace(widths, startCol, endCol, cellSpan - spanWidth);
- }
- }
- }
- }
-
- if (mode == 0 || mode == 1) {
- return widths;
- }
-
- if (pass == 0 && this.getColumnSum(widths) <= width) {
- return widths;
- }
- }
-
- int diff = width - this.getColumnSum(widths);
- if (diff > 0) {
- widths = this.distributeSpace(widths, 0, widths.length - 1, diff);
- }
-
- return widths;
- }
-
- int[] computePercentColumnWidths(int width) {
- float[] pctValues = new float[this.m_pctColWidths.length];
- float totalPctCols = 0.0F;
- int nNonPctCols = 0;
-
- for(int i = 0; i < pctValues.length; ++i) {
- pctValues[i] = this.m_pctColWidths[i];
- if (pctValues[i] > 0.0F) {
- totalPctCols += pctValues[i];
- } else {
- ++nNonPctCols;
- }
- }
-
- float nonPctCols = 1.0F - totalPctCols;
- int[] widths = new int[this.m_nColumns];
-
- for(int i = 0; i < this.m_nColumns; ++i) {
- widths[i] = Math.max(this.m_colSpecWidths[i], this.m_minColWidths[i]);
- }
-
- int layoutWidth = this.computeRequiredLayoutWidth(pctValues, totalPctCols, this.m_minColWidths);
- int availWidth = width;
- if (this.m_width != -1 || this.m_pctValue > 0.0F && this.m_pctValue <= 1.0F) {
- if (this.m_width != -1) {
- availWidth = this.m_width;
- } else {
- availWidth = (int)(this.m_pctValue * (float)width);
- }
-
- if (layoutWidth < availWidth) {
- layoutWidth = availWidth;
- }
- }
-
- if (layoutWidth < availWidth) {
- int prefLayoutWidth = this.computeRequiredLayoutWidth(pctValues, totalPctCols, this.m_prefColWidths);
- if (prefLayoutWidth <= availWidth) {
- layoutWidth = prefLayoutWidth;
- } else {
- layoutWidth = availWidth;
- }
- }
-
- if (layoutWidth <= width) {
- int tabWidth = layoutWidth;
- int totPctSpace = 0;
-
- for(int i = 0; i < pctValues.length; ++i) {
- if ((double)pctValues[i] > (double)0.0F) {
- widths[i] = (int)(pctValues[i] * (float)tabWidth);
- totPctSpace += widths[i];
- }
- }
-
- int space = Math.max(0, tabWidth - totPctSpace);
-
- while(nNonPctCols > 0 && space > 0) {
- boolean bColsAvailable = false;
-
- for(int i = 0; i < this.m_nColumns; ++i) {
- if ((double)pctValues[i] <= (double)0.0F && this.m_colSpecWidths[i] == -1 || widths[i] < this.m_colSpecWidths[i]) {
- bColsAvailable = true;
- break;
- }
- }
-
- if (!bColsAvailable) {
- break;
- }
-
- for(int i = 0; i < pctValues.length && space > 0; ++i) {
- if ((double)pctValues[i] <= (double)0.0F) {
- int var10002 = widths[i]++;
- --space;
- }
- }
- }
-
- int overshoot = this.getColumnSum(widths) - tabWidth;
- if (overshoot > 0) {
- boolean bAllMinimum = this.allMinimum(widths);
- boolean bAllSpecWidths = this.allSpecWidths(widths);
-
- while(!bAllMinimum && overshoot > 0) {
- for(int i = 0; i < widths.length && overshoot > 0; ++i) {
- if (!bAllSpecWidths) {
- if (this.m_colSpecWidths[i] != -1 && widths[i] > this.m_colSpecWidths[i] && widths[i] > this.m_minColWidths[i]) {
- int var32 = widths[i]--;
- --overshoot;
- }
- } else if (widths[i] > this.m_minColWidths[i]) {
- int var33 = widths[i]--;
- --overshoot;
- }
- }
-
- bAllMinimum = this.allMinimum(widths);
- if (!bAllSpecWidths) {
- bAllSpecWidths = this.allSpecWidths(widths);
- }
- }
- } else {
- space = Math.abs(overshoot);
-
- while(space > 0) {
- for(int i = 0; i < pctValues.length && space > 0; ++i) {
- if ((double)pctValues[i] > (double)0.0F) {
- int var34 = widths[i]++;
- --space;
- }
- }
- }
- }
- } else {
- for(int i = 0; i < pctValues.length; ++i) {
- if ((double)pctValues[i] > (double)0.0F) {
- widths[i] = Math.max(this.m_minColWidths[i], (int)(pctValues[i] * (float)width));
- } else {
- widths[i] = Math.max(this.m_colSpecWidths[i], this.m_minColWidths[i]);
- }
- }
-
- int overshoot = this.getColumnSum(widths) - width;
- if (overshoot < 0) {
- int space = Math.abs(overshoot);
-
- while(nNonPctCols > 0 && space > 0) {
- for(int i = 0; i < pctValues.length; ++i) {
- if ((double)pctValues[i] <= (double)0.0F) {
- int var35 = widths[i]++;
- --space;
- }
- }
- }
- } else {
- boolean bAllMinimum = this.allMinimum(widths);
- boolean bAllSpecWidths = this.allSpecWidths(widths);
-
- while(!bAllMinimum && overshoot > 0) {
- for(int i = 0; i < widths.length && overshoot > 0; ++i) {
- if (!bAllSpecWidths) {
- if (this.m_colSpecWidths[i] != -1 && widths[i] > this.m_colSpecWidths[i]) {
- int var36 = widths[i]--;
- --overshoot;
- }
- } else if (widths[i] > this.m_minColWidths[i]) {
- int var37 = widths[i]--;
- --overshoot;
- }
- }
-
- bAllMinimum = this.allMinimum(widths);
- if (!bAllSpecWidths) {
- bAllSpecWidths = this.allSpecWidths(widths);
- }
- }
- }
- }
-
- return widths;
- }
-
- void computePrefMinWidths() {
- if (!this.m_bPrefMinColsComputed) {
- this.m_bPrefMinColsComputed = true;
- this.m_hasSingleCell = new boolean[this.m_nColumns];
- this.m_prefColWidths = new int[this.m_nColumns];
- this.m_minColWidths = new int[this.m_nColumns];
-
- for(int col = 0; col < this.m_nColumns; ++col) {
- boolean bFoundSingleCell = false;
-
- for(int row = 0; row < super.m_children.length; ++row) {
- TableRow rv = (TableRow)super.m_children[row];
- TableCell cell = rv.getTableColumn(col);
- if (cell != null) {
- this.m_prefColWidths[col] = Math.max(this.m_prefColWidths[col], cell.getPreferredSpan(1));
- this.m_minColWidths[col] = Math.max(this.m_minColWidths[col], cell.getMinimumSpan(1));
- bFoundSingleCell = true;
- }
- }
-
- this.m_hasSingleCell[col] = bFoundSingleCell;
- }
-
- for(int row = 0; row < super.m_children.length; ++row) {
- TableRow rv = (TableRow)super.m_children[row];
-
- for(int col = 0; col < rv.m_children.length; ++col) {
- TableCell cell = (TableCell)rv.m_children[col];
- if (cell != null && cell.m_colSpan > 1) {
- int minSpan = cell.getMinimumSpan(1);
- int prefSpan = cell.getPreferredSpan(1);
- int currentMinSpan = 0;
- int currentPrefSpan = 0;
- int start = cell.m_startColumn;
- int end = cell.m_endColumn;
-
- for(int i = start; i <= end && i < this.m_minColWidths.length; ++i) {
- currentMinSpan += this.m_minColWidths[i];
- currentPrefSpan += this.m_prefColWidths[i];
- }
-
- if (currentMinSpan < minSpan) {
- this.doWeightedDistribution(this.m_minColWidths, start, end, minSpan - currentMinSpan);
- }
- }
- }
- }
-
- }
- }
-
- int computeRequiredLayoutWidth(float[] pctValues, float totalPctCols, int[] widths) {
- int requiredWidth = 0;
- int nonPctWidths = 0;
-
- for(int i = 0; i < pctValues.length; ++i) {
- if ((double)pctValues[i] > (double)0.0F) {
- int w = (int)((float)widths[i] / pctValues[i]);
- requiredWidth = Math.max(w, requiredWidth);
- } else {
- nonPctWidths += widths[i];
- }
- }
-
- float nonPctCols = 1.0F - totalPctCols;
- int nonPctNeeded = 0;
- if (nonPctCols > 0.0F) {
- nonPctNeeded = (int)((float)nonPctWidths / nonPctCols);
- }
-
- requiredWidth = Math.max(requiredWidth, nonPctNeeded);
- return requiredWidth;
- }
-
- int[] distributeSpace(int[] colWidths, int startCol, int endCol, int amount) {
- int nCols = endCol - startCol + 1;
- int prefSum = 0;
- int colSum = 0;
- boolean bWeighted = true;
-
- for(int i = startCol; i <= endCol; ++i) {
- prefSum += this.m_prefColWidths[i];
- colSum += colWidths[i];
- if (!this.m_hasSingleCell[i]) {
- bWeighted = false;
- }
- }
-
- if (colSum + amount >= prefSum) {
- int[] differences = new int[nCols];
- int i = startCol;
-
- for(int j = 0; i <= endCol; ++j) {
- if (this.m_hasSingleCell[i]) {
- differences[j] = this.m_prefColWidths[i] - colWidths[i];
- } else {
- differences[j] = -1;
- }
-
- ++i;
- }
-
- int space = amount;
- int i = startCol;
-
- for(int j = 0; i <= endCol; ++j) {
- if (differences[j] > 0) {
- colWidths[i] += differences[j];
- space -= differences[j];
- }
-
- ++i;
- }
-
- if (space > 0) {
- colWidths = this.doEvenDistribution(colWidths, startCol, endCol, space);
- }
- } else {
- colWidths = this.doEvenDistribution(colWidths, startCol, endCol, amount);
- }
-
- return colWidths;
- }
-
- int[] doEvenDistribution(int[] colWidths, int startCol, int endCol, int amount) {
- int nCols = endCol - startCol + 1;
-
- do {
- int nDiffs = 0;
- int[] diffs = new int[nCols];
- int i = startCol;
-
- for(int j = 0; i <= endCol; ++j) {
- diffs[j] = this.m_prefColWidths[i] - colWidths[i];
- if (diffs[j] > 0) {
- ++nDiffs;
- }
-
- ++i;
- }
-
- if (nDiffs > 0) {
- int apportion = Math.max(1, amount / nDiffs);
- int i = 0;
-
- for(int j = startCol; i < nCols && amount > 0; ++j) {
- if (diffs[i] > 0) {
- if (diffs[i] > apportion) {
- amount -= apportion;
- colWidths[j] += apportion;
- } else {
- amount -= diffs[i];
- colWidths[j] += diffs[i];
- }
- }
-
- ++i;
- }
- } else if (amount >= nCols) {
- int origAmount = amount;
- int apportion = amount / nCols;
- int runningTotal = 0;
- int addAmount = 0;
- int i = 0;
-
- for(int j = startCol; i < nCols; ++j) {
- if (i == nCols - 1) {
- addAmount = origAmount - runningTotal;
- } else {
- addAmount = apportion;
- }
-
- colWidths[j] += addAmount;
- runningTotal += addAmount;
- amount -= addAmount;
- ++i;
- }
- } else {
- for(int j = startCol; j < amount; ++j) {
- int var10002 = colWidths[j]++;
- }
-
- amount = 0;
- }
- } while(amount > 0);
-
- return colWidths;
- }
-
- boolean doWeightedDistribution(int[] colWidths, int startCol, int endCol, int amount) {
- int nCols = endCol - startCol + 1;
- int prefSum = this.getColumnSum(this.m_prefColWidths);
- int runningTotal = 0;
- int addAmount = 0;
-
- for(int i = startCol; i <= endCol; ++i) {
- if (i == endCol) {
- addAmount = amount - runningTotal;
- } else {
- addAmount = (int)((double)this.m_prefColWidths[i] / (double)prefSum * (double)amount);
- }
-
- colWidths[i] += addAmount;
- runningTotal += addAmount;
- }
-
- return runningTotal == amount;
- }
-
- protected View elementToView(Element e) {
- if (super.m_elem == e) {
- return this;
- } else {
- for(int i = 0; i < super.m_children.length; ++i) {
- View v = super.m_children[i].elementToView(e);
- if (v != null) {
- return v;
- }
- }
-
- for(int i = 0; i < this.m_topCaptions.length; ++i) {
- View v = this.m_topCaptions[i].elementToView(e);
- if (v != null) {
- return v;
- }
- }
-
- for(int i = 0; i < this.m_bottomCaptions.length; ++i) {
- View v = this.m_bottomCaptions[i].elementToView(e);
- if (v != null) {
- return v;
- }
- }
-
- return null;
- }
- }
-
- int getColumnSum(int[] cols) {
- int colSum = 0;
-
- for(int i = 0; i < cols.length; ++i) {
- colSum += cols[i];
- }
-
- return colSum;
- }
-
- public int getMinimumSpan(int axis) {
- if (axis != 1) {
- return 0;
- } else if (super.m_minWidth != -1) {
- return super.m_minWidth;
- } else {
- int m_minWidth = 0;
- this.computePrefMinWidths();
- int[] colWidths = this.computeColumnWidths(0, 1);
-
- for(int i = 0; i < colWidths.length; ++i) {
- m_minWidth += colWidths[i];
- }
-
- m_minWidth += this.m_borderSize * 2 + 2 * this.m_cellSpacing;
- if (this.m_width != -1 && this.m_width > m_minWidth) {
- m_minWidth = this.m_width;
- }
-
- return m_minWidth;
- }
- }
-
- protected int getPreferredSpan(int axis) {
- if (axis != 1) {
- return 0;
- } else if (super.m_prefWidth != -1) {
- return super.m_prefWidth;
- } else {
- int m_prefWidth = 0;
- this.computePrefMinWidths();
- int[] colWidths = this.computeColumnWidths(0, 0);
-
- for(int i = 0; i < colWidths.length; ++i) {
- m_prefWidth += colWidths[i];
- }
-
- m_prefWidth += this.m_cellSpacing * (this.m_nColumns - 1);
- m_prefWidth += this.m_borderSize * 2 + this.m_cellSpacing * 2;
- if (this.m_width != -1 && this.m_width > 0) {
- int specWidth = this.m_width;
- int minWidth = this.getMinimumSpan(1);
- if (m_prefWidth > specWidth && specWidth >= minWidth) {
- m_prefWidth = specWidth;
- } else {
- m_prefWidth = minWidth;
- }
- }
-
- return m_prefWidth;
- }
- }
-
- protected TableRow getRow(int row) {
- return row < super.m_children.length ? (TableRow)super.m_children[row] : null;
- }
-
- protected void increasePreviousCellHeights(TableRow row, int yAmount) {
- int rowIndex;
- for(rowIndex = 0; rowIndex < super.m_children.length; ++rowIndex) {
- TableRow rv = (TableRow)super.m_children[rowIndex];
- if (rv == row) {
- break;
- }
- }
-
- for(int i = 0; i <= rowIndex - 1; ++i) {
- TableRow rv = (TableRow)super.m_children[i];
-
- for(int j = 0; j < rv.m_children.length; ++j) {
- TableCell cell = (TableCell)rv.m_children[j];
- if (rowIndex >= cell.m_startRow && rowIndex <= cell.m_endRow) {
- cell.increaseHeight(yAmount);
- }
- }
- }
-
- }
-
- protected void increaseRowHeight(int row, int amt) {
- if (row < super.m_children.length) {
- TableRow rv = (TableRow)super.m_children[row];
- rv.increaseHeight(amt);
-
- for(int i = row + 1; i < super.m_children.length; ++i) {
- ((TableRow)super.m_children[i]).move(0, amt, true);
- }
-
- }
- }
-
- protected void init() {
- String b = (String)super.m_elem.getAttribute("border");
- if (b == null) {
- this.m_borderSize = 0;
- } else {
- this.m_borderSize = Utilities.setIntegerProperty(1, "border", super.m_elem.getAttributes());
- }
-
- this.m_bgColor = Utilities.setColorProperty((Color)null, "bgcolor", super.m_elem.getAttributes());
- this.m_height = Utilities.setIntegerProperty(-1, "height", super.m_elem.getAttributes());
- this.m_width = Utilities.setIntegerProperty(-1, "width", super.m_elem.getAttributes());
- this.m_pctValue = -1.0F;
- if (this.m_width == -1) {
- this.m_pctValue = Utilities.setPercentageProperty(-1.0F, "width", super.m_elem.getAttributes());
- }
-
- this.m_cellPadding = Utilities.setIntegerProperty(1, "cellpadding", super.m_elem.getAttributes());
- this.m_cellSpacing = Utilities.setIntegerProperty(1, "cellspacing", super.m_elem.getAttributes());
- super.m_alignment = Utilities.setAlignmentProperty(false, -1, "align", super.m_elem.getAttributes());
- }
-
- protected void initCellColumnRowValues() {
- if (super.m_children != null) {
- int nRows = super.m_children.length;
- TableRow currentRow = null;
- Vector occupiedColumns = new Vector();
- this.m_nColumns = 0;
- this.m_nRows = nRows;
- int colPos = 0;
-
- for(int row = 0; row < nRows; ++row) {
- this.m_nColumns = Math.max(this.m_nColumns, colPos);
- colPos = 0;
- this.removeInvalidOccupiedColumns(occupiedColumns, row);
- currentRow = (TableRow)super.m_children[row];
- int rowExtension = currentRow.getBiggestRowSpan();
- this.m_nRows = Math.max(this.m_nRows, row + rowExtension);
- int nRowCells = currentRow.m_children.length;
- int cellIndex = 0;
-
- while(cellIndex < nRowCells) {
- if (this.columnOccupied(occupiedColumns, row, colPos)) {
- ++colPos;
- } else {
- TableCell cell = currentRow.getCell(cellIndex);
- cell.setTableColumns(colPos);
- colPos += cell.m_colSpan;
- cell.setTableRows(row);
- if (cell.m_rowSpan > 1) {
- RowSpanColumns item = new RowSpanColumns(this);
- item.columns = new int[cell.m_colSpan];
- int startCol = cell.m_startColumn;
-
- for(int j = 0; j < item.columns.length; ++j) {
- item.columns[j] = startCol + j;
- }
-
- item.endRow = cell.m_endRow;
- occupiedColumns.addElement(item);
- }
-
- ++cellIndex;
- }
- }
- }
-
- this.m_nColumns = Math.max(this.m_nColumns, colPos);
- }
- }
-
- protected void initColumnSpecs() {
- this.m_colSpecWidths = new int[this.m_nColumns];
-
- for(int i = 0; i < this.m_colSpecWidths.length; ++i) {
- this.m_colSpecWidths[i] = -1;
- }
-
- this.m_pctColWidths = new float[this.m_nColumns];
-
- for(int i = 0; i < this.m_pctColWidths.length; ++i) {
- this.m_pctColWidths[i] = -1.0F;
- }
-
- for(int col = 0; col < this.m_nColumns; ++col) {
- for(int row = 0; row < super.m_children.length; ++row) {
- TableRow rv = (TableRow)super.m_children[row];
- TableCell cell = rv.getTableColumn(col);
- if (cell != null) {
- String width = (String)((View)cell).getAttribute("width");
- if (width != null) {
- int idx = width.indexOf("%");
- if (idx > 0) {
- width = width.substring(0, idx);
- Integer iVal = Utilities.getInteger(width);
- if (iVal != null && iVal > 0 && iVal <= 100) {
- this.m_pctColWidths[col] = (float)iVal / 100.0F;
- this.m_bHavePctColumns = true;
- }
- } else {
- this.m_colSpecWidths[col] = Math.max(this.m_colSpecWidths[col], cell.m_width);
- }
- }
- }
- }
- }
-
- }
-
- protected void initRowSpecs() {
- this.m_rowHeightSpecs = new int[this.m_nRows];
-
- for(int i = 0; i < this.m_nRows; ++i) {
- if (i < super.m_children.length) {
- TableRow rv = (TableRow)super.m_children[i];
- this.m_rowHeightSpecs[i] = rv.getHeightSpec();
- } else {
- this.m_rowHeightSpecs[i] = -1;
- }
- }
-
- }
-
- protected void invalidate() {
- this.m_bPrefMinColsComputed = false;
- super.invalidate();
- }
-
- protected boolean isFloater() {
- return super.m_alignment == 0 || super.m_alignment == 2;
- }
-
- protected boolean isSelfContained() {
- return true;
- }
-
- protected Rectangle layout(int x, int y, int width, LayoutInfo info) {
- super.m_bounds.setBounds(x, y, 0, 0);
- int xPos = x + super.m_insets.left;
- int yPos = y + super.m_insets.top;
- width -= super.m_insets.left + super.m_insets.right + info.leftMargin;
- int layoutWidth = Math.max(0, width);
- if (this.m_width != -1) {
- layoutWidth = this.m_width;
- } else if (this.m_pctValue > 0.0F && this.m_pctValue <= 1.0F) {
- layoutWidth = (int)(this.m_pctValue * (float)width);
- }
-
- layoutWidth -= 2 * this.m_borderSize;
- int cellSpacing = this.m_cellSpacing;
- layoutWidth -= (this.m_nColumns - 1) * cellSpacing + 2 * cellSpacing;
- layoutWidth = Math.max(0, layoutWidth);
- this.computePrefMinWidths();
- this.m_colWidths = this.layoutColumns(layoutWidth, 2);
- this.checkWidthSpecification(layoutWidth);
- xPos += this.m_borderSize + cellSpacing;
- yPos += this.m_borderSize + cellSpacing;
- super.m_bounds = this.layoutRows(xPos, yPos, layoutWidth, info);
- super.m_bounds.x = x;
- super.m_bounds.y = y;
- Rectangle var10000 = super.m_bounds;
- var10000.width += 2 * this.m_borderSize + super.m_insets.left + super.m_insets.right;
- var10000 = super.m_bounds;
- var10000.height += 2 * this.m_borderSize + super.m_insets.top + super.m_insets.bottom;
- this.m_tableBorder = new Rectangle(super.m_bounds);
- Rectangle r = this.layoutCaptions(x, y, super.m_bounds.width, this.m_topCaptions);
- var10000 = super.m_bounds;
- var10000.height += r.height;
- super.m_bounds.width = Math.max(super.m_bounds.width, r.width);
- if (r.height > 0 && super.m_children.length > 0) {
- this.moveRows(r.height, (TableRow)super.m_children[0]);
- }
-
- var10000 = this.m_tableBorder;
- var10000.y += r.height;
- r = this.layoutCaptions(x, super.m_bounds.y + super.m_bounds.height, super.m_bounds.width, this.m_bottomCaptions);
- var10000 = super.m_bounds;
- var10000.height += r.height;
- return super.m_bounds;
- }
-
- Rectangle layoutCaptions(int x, int y, int width, View[] captions) {
- Rectangle bounds = new Rectangle(x, y, 0, 0);
- int xPos = x;
- int yPos = y;
-
- for(int i = 0; i < captions.length; ++i) {
- Rectangle r = captions[i].layout(xPos, yPos, width, new LayoutInfo());
- yPos += r.height;
- bounds.width = Math.max(bounds.width, r.width);
- }
-
- bounds.height = yPos - y;
- return bounds;
- }
-
- int[] layoutColumns(int width, int mode) {
- return this.m_bHavePctColumns ? this.computePercentColumnWidths(width) : this.computeColumnWidths(width, 2);
- }
-
- Rectangle layoutRows(int x, int y, int width, LayoutInfo info) {
- int xPos = x;
- int yPos = y;
- int tableHeight = 0;
- int tableWidth = 0;
- int nValidRows = 0;
- int[] rowHeights = new int[this.m_nRows];
-
- for(int h = 0; h < this.m_nRows; ++h) {
- rowHeights[h] = 0;
- }
-
- for(int row = 0; row < super.m_children.length; ++row) {
- TableRow rv = (TableRow)super.m_children[row];
- rv.m_colWidths = this.m_colWidths;
- Rectangle bounds = rv.layoutSingleRowCells(xPos, yPos, width, info);
- rowHeights[row] = bounds.height;
- if (bounds.height != 0) {
- ++nValidRows;
- yPos += bounds.height;
- yPos += this.m_cellSpacing;
- }
- }
-
- xPos = x;
- yPos = y;
-
- for(int row = 0; row < super.m_children.length; ++row) {
- TableRow rv = (TableRow)super.m_children[row];
- rowHeights = rv.layoutMultiRowCells(xPos, yPos, width, rowHeights, info);
- ++nValidRows;
- yPos += rowHeights[row];
- yPos += this.m_cellSpacing;
- }
-
- if (this.m_height != -1) {
- int tabHeight = 0;
-
- for(int row = 0; row < rowHeights.length; ++row) {
- tabHeight += rowHeights[row];
- if (rowHeights[row] > 0 && this.m_cellSpacing > 0) {
- tabHeight += this.m_cellSpacing;
- }
- }
-
- int[] diffs = new int[rowHeights.length];
-
- while(this.m_height > tabHeight) {
- for(int row = 0; row < rowHeights.length; ++row) {
- int var10002 = rowHeights[row]++;
- var10002 = diffs[row]++;
- ++tabHeight;
- if (tabHeight >= this.m_height) {
- break;
- }
- }
- }
-
- for(int row = 0; row < super.m_children.length && row < diffs.length; ++row) {
- if (diffs[row] > 0) {
- ((TableRow)super.m_children[row]).increaseHeight(diffs[row]);
- if (row + 1 < super.m_children.length) {
- this.moveRows(diffs[row], (TableRow)super.m_children[row + 1]);
- }
- }
- }
- }
-
- for(int row = 0; row < super.m_children.length; ++row) {
- rowHeights = ((TableRow)super.m_children[row]).setCellHeights(rowHeights, info);
- }
-
- super.m_bounds.setBounds(x, y, 0, this.m_cellSpacing);
-
- for(int row = 0; row < rowHeights.length; ++row) {
- Rectangle var10000 = super.m_bounds;
- var10000.height += rowHeights[row];
- if (rowHeights[row] > 0 && this.m_cellSpacing > 0) {
- var10000 = super.m_bounds;
- var10000.height += this.m_cellSpacing;
- }
- }
-
- for(int row = 0; row < super.m_children.length; ++row) {
- TableRow rv = (TableRow)super.m_children[row];
- rv.computeCellBorders();
- super.m_bounds.width = Math.max(super.m_bounds.width, ((View)rv).getBounds().width);
- }
-
- Rectangle var31 = super.m_bounds;
- var31.width += 2 * this.m_cellSpacing;
- return super.m_bounds;
- }
-
- protected void loadResources() {
- for(int i = 0; i < super.m_children.length; ++i) {
- super.m_children[i].loadResources();
- }
-
- for(int i = 0; i < this.m_topCaptions.length; ++i) {
- this.m_topCaptions[i].loadResources();
- }
-
- for(int i = 0; i < this.m_bottomCaptions.length; ++i) {
- this.m_bottomCaptions[i].loadResources();
- }
-
- }
-
- protected void makeChildren(ViewFactory factory) {
- int nCount = super.m_elem.getElementCount();
- View[] childViews = new View[nCount];
- int nValidRows = 0;
- Vector topCaptions = new Vector();
- Vector botCaptions = new Vector();
-
- for(int i = 0; i < nCount; ++i) {
- Element childElement = super.m_elem.getElementAt(i);
- if (childElement.getType() == 3) {
- childViews[nValidRows++] = new TableRow(this, childElement, super.m_container);
- } else if (childElement.getType() == 45) {
- boolean bTop = true;
- String align = (String)childElement.getAttribute("align");
- if (align != null) {
- bTop = !align.equalsIgnoreCase("bottom");
- }
-
- View capView = new BlockView(this, childElement, super.m_container);
- capView.m_alignment = 1;
- if (bTop) {
- topCaptions.addElement(capView);
- } else {
- botCaptions.addElement(capView);
- }
- }
- }
-
- this.m_topCaptions = new View[topCaptions.size()];
- topCaptions.copyInto(this.m_topCaptions);
-
- for(int i = 0; i < this.m_topCaptions.length; ++i) {
- this.m_topCaptions[i].makeChildren(factory);
- }
-
- this.m_bottomCaptions = new View[botCaptions.size()];
- botCaptions.copyInto(this.m_bottomCaptions);
-
- for(int i = 0; i < this.m_bottomCaptions.length; ++i) {
- this.m_bottomCaptions[i].makeChildren(factory);
- }
-
- this.m_nDefinedRows = nValidRows;
- super.m_children = new View[nValidRows];
-
- for(int i = 0; i < nValidRows; ++i) {
- super.m_children[i] = childViews[i];
- }
-
- for(int i = 0; i < super.m_children.length; ++i) {
- View child = super.m_children[i];
- if (child != null) {
- child.makeChildren(factory);
- }
- }
-
- this.initCellColumnRowValues();
- this.initColumnSpecs();
- this.initRowSpecs();
- this.notifyBorderSize();
- }
-
- protected View modelToView(int pos) {
- if (pos >= super.m_elem.m_p0 && pos <= super.m_elem.m_p1) {
- return this;
- } else {
- for(int i = 0; i < super.m_children.length; ++i) {
- View v = super.m_children[i].modelToView(pos);
- if (v != null) {
- return v;
- }
- }
-
- for(int i = 0; i < this.m_topCaptions.length; ++i) {
- View v = this.m_topCaptions[i].modelToView(pos);
- if (v != null) {
- return v;
- }
- }
-
- for(int i = 0; i < this.m_bottomCaptions.length; ++i) {
- View v = this.m_bottomCaptions[i].modelToView(pos);
- if (v != null) {
- return v;
- }
- }
-
- return null;
- }
- }
-
- public void move(int x, int y, boolean bMoveFloaters) {
- for(int i = 0; i < super.m_children.length; ++i) {
- super.m_children[i].move(x, y, bMoveFloaters);
- }
-
- Rectangle var10000 = super.m_bounds;
- var10000.x += x;
- var10000 = super.m_bounds;
- var10000.y += y;
- var10000 = this.m_tableBorder;
- var10000.x += x;
- var10000 = this.m_tableBorder;
- var10000.y += y;
- }
-
- protected void moveRows(int yAmount, TableRow startRow) {
- for(int i = 0; i < super.m_children.length; ++i) {
- if (startRow == super.m_children[i]) {
- for(int j = i; j < super.m_children.length; ++j) {
- ((TableRow)super.m_children[j]).move(0, yAmount, true);
- }
- break;
- }
- }
-
- }
-
- protected void notifyBorderSize() {
- int cellBorderSize = this.m_borderSize > 0 ? 1 : 0;
-
- for(int row = 0; row < super.m_children.length; ++row) {
- TableRow rv = (TableRow)super.m_children[row];
-
- for(int cell = 0; cell < rv.m_children.length; ++cell) {
- ((TableCell)rv.m_children[cell]).m_borderSize = cellBorderSize;
- }
- }
-
- }
-
- protected int pageBreakAdjust(LayoutInfo info) {
- int adjustment = 0;
-
- for(int row = 0; row < super.m_children.length; ++row) {
- int rowAdjustment = super.m_children[row].pageBreakAdjust(info);
- if (rowAdjustment > 0 && row != super.m_children.length - 1) {
- for(int j = row + 1; j < super.m_children.length; ++j) {
- super.m_children[j].move(0, rowAdjustment, true);
- }
- }
-
- adjustment += rowAdjustment;
- }
-
- Rectangle var10000 = super.m_bounds;
- var10000.height += adjustment;
- return adjustment;
- }
-
- public void paint(Graphics g, Shape alloc) {
- Rectangle clip = alloc.getBounds();
- if (super.m_bounds.intersects(clip)) {
- for(int i = 0; i < this.m_topCaptions.length; ++i) {
- this.m_topCaptions[i].paint(g, alloc);
- }
-
- for(int i = 0; i < this.m_bottomCaptions.length; ++i) {
- this.m_bottomCaptions[i].paint(g, alloc);
- }
-
- for(int i = 0; i < super.m_children.length; ++i) {
- super.m_children[i].paint(g, alloc);
- }
-
- this.paintBorder(g);
- }
-
- }
-
- protected void paintBackground(Graphics g) {
- if (this.m_bgColor != null && super.m_bounds != null) {
- Color oldColor = g.getColor();
- g.setColor(this.m_bgColor);
- g.fillRect(super.m_bounds.x, super.m_bounds.y, super.m_bounds.width, super.m_bounds.height);
- g.setColor(oldColor);
- }
-
- }
-
- protected void paintBorder(Graphics g) {
- Color oldColor = g.getColor();
- int x = this.m_tableBorder.x + super.m_insets.left;
- int y = this.m_tableBorder.y + super.m_insets.top;
- int w = this.m_tableBorder.width - 1 - (super.m_insets.left + super.m_insets.right);
- int h = this.m_tableBorder.height - 1 - (super.m_insets.bottom + super.m_insets.top);
- g.setColor(Utilities.getBrightBorderColor());
-
- for(int i = 0; i < this.m_borderSize; ++i) {
- g.drawLine(x + i, y + i, x + w - i, y + i);
- g.drawLine(x + i, y + i, x + i, y + h - i);
- }
-
- g.setColor(Utilities.getDarkBorderColor());
-
- for(int i = 0; i < this.m_borderSize; ++i) {
- g.drawLine(x + i, y + h - i, x + w - i, y + h - i);
- g.drawLine(x + w - i, y + i, x + w - i, y + h - i);
- }
-
- g.setColor(oldColor);
- }
-
- protected void paintFocusBox(Graphics g, Shape alloc) {
- Rectangle clip = alloc.getBounds();
- if (super.m_bounds.intersects(clip)) {
- for(int i = 0; i < this.m_topCaptions.length; ++i) {
- this.m_topCaptions[i].paintFocusBox(g, alloc);
- }
-
- for(int i = 0; i < this.m_bottomCaptions.length; ++i) {
- this.m_bottomCaptions[i].paintFocusBox(g, alloc);
- }
-
- for(int i = 0; i < super.m_children.length; ++i) {
- super.m_children[i].paintFocusBox(g, alloc);
- }
- }
-
- }
-
- protected void removeInvalidOccupiedColumns(Vector v, int row) {
- Vector temp = new Vector();
- Enumeration e = v.elements();
-
- while(e.hasMoreElements()) {
- RowSpanColumns x = (RowSpanColumns)e.nextElement();
- if (row <= x.endRow) {
- temp.addElement(x);
- }
- }
-
- }
-
- protected ElementViewInfo viewToModel(int x, int y) {
- ElementViewInfo info = null;
- if (super.m_bounds.contains(x, y)) {
- for(int i = 0; i < super.m_children.length; ++i) {
- info = super.m_children[i].viewToModel(x, y);
- if (info != null) {
- break;
- }
- }
-
- if (info == null) {
- for(int i = 0; i < this.m_topCaptions.length; ++i) {
- info = this.m_topCaptions[i].viewToModel(x, y);
- if (info != null) {
- break;
- }
- }
- }
-
- if (info == null) {
- for(int i = 0; i < this.m_bottomCaptions.length; ++i) {
- info = this.m_bottomCaptions[i].viewToModel(x, y);
- if (info != null) {
- break;
- }
- }
- }
-
- if (info == null) {
- info = new ElementViewInfo(super.m_elem, this);
- }
- }
-
- return info;
- }
- }
-